package org.grottarossa.ui.core;


import org.grottarossa.ui.core.base.BasePanelView;

import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.Window;

public class PopupViewer
{
	public Window showInPopup(Component view, int width, int height, String caption,
			boolean sizable, boolean modal, Window activeWindow)
	{
		Window popup = new Window(caption);
		activeWindow.getApplication().getMainWindow().addWindow(popup);

		popup.setResizable(sizable);
		popup.setModal(modal);
		popup.getLayout().setWidth(width, Sizeable.UNITS_PIXELS);
		popup.getLayout().setHeight(height, Sizeable.UNITS_PIXELS);
		popup.addComponent(view);
		view.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		view.setHeight(100, Sizeable.UNITS_PERCENTAGE);

		return popup;
	}

	public void removePopupFromWindow(Window popup, Window activeWindow)
	{
		activeWindow.getApplication().getMainWindow().removeWindow(popup);
	}

	public void openUrl(String url, Window parent)
	{
		Window popup = new Window();
		parent.getApplication().getMainWindow().addWindow(popup);
		popup.open(new ExternalResource(url));
	}
}
